package com.example.surface.zyfypt_207zjh.fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.surface.zyfypt_207zjh.R;
import com.example.surface.zyfypt_207zjh.adapter.ZJHAdapter;
import com.example.surface.zyfypt_207zjh.bean.SessionIDBean;
import com.example.surface.zyfypt_207zjh.bean.ZJhBean;
import com.example.surface.zyfypt_207zjh.iface.ZJHListener;
import com.example.surface.zyfypt_207zjh.model.ZJHModel;

import java.util.List;


public class CaseFragment extends Fragment {
    private RecyclerView rv;//RecyclerView 控件
    private RecyclerView.LayoutManager lm;//RecyclerView控件布局
    private ZJHAdapter ma;//RecyclerView
    private List<ZJhBean> list = null;
    //private TextView tvinfo;
    private SessionIDBean sessionIDBean;

    ZJHListener articleListener=new ZJHListener() {
        @Override
        public void onResponse(List<ZJhBean> beanList) {
            list=beanList;//获取文章
            ma.setList(list);
            ma.notifyDataSetChanged();//通知更新
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getActivity(),"失败："+msg, Toast.LENGTH_SHORT);
        }
    };
    //private TextView tvinfo;
    private View view=null;
    private Context context;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context=getActivity();
        //动态加载Fragment1的布局文件
        view=inflater.inflate(R.layout.fragment_case,container,false);
        //获取布局上的控件，注意通过view获取
        //tvinfo=(TextView)view.findViewById(R.id.textView8);
        //tvinfo.setText("微信");
        //返回动态生成的view
        initRecyclerView();
        ZJHModel model=new ZJHModel();
        sessionIDBean=new SessionIDBean();
        model.getResultList("tcase",1,sessionIDBean.getSessionIDBean,articleListener);
        return view;
    }
    private void initRecyclerView(){
        rv = (RecyclerView)view.findViewById(R.id.recycleView_case);
        //创建默认线性布局
        lm= new LinearLayoutManager(getActivity());
        //设置布局管理器
        rv.setLayoutManager(lm);
        //固定每个item高度，可以提高性能
        rv.setHasFixedSize(true);
        //获取数据
        //list=getData();
        //实例化Adapter
        ma= new ZJHAdapter(getActivity());
        //传进数据
        ma.setList(list);
        //绑定RecyclerView和Adaper
        rv.setAdapter(ma);
    }

}
